package com.shop.web.shop;

import java.util.List;

import com.shop.shop.domain.ShopCar;
import com.shop.shop.service.IShopCarService;
import com.vip.common.annotation.Log;
import com.vip.common.core.controller.BaseController;
import com.vip.common.core.domain.AjaxResult;
import com.vip.common.core.page.TableDataInfo;
import com.vip.common.enums.BusinessType;
import com.vip.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 购物车Controller
 * 
 * @author
 */
@Api(tags = "购物车接口")
@RestController
@RequestMapping("/system/car")
public class ShopCarController extends BaseController
{
    @Autowired
    private IShopCarService shopCarService;

    /**
     * 查询购物车列表
     */
    @ApiOperation(value = "查询购物车列表")
    @GetMapping("/list")
    public TableDataInfo list(ShopCar shopCar)
    {
        startPage();
        List<ShopCar> list = shopCarService.selectShopCarList(shopCar);
        return getDataTable(list);
    }

    /**
     * 导出购物车列表
     */
    @ApiOperation(value = "导出购物车列表")
    @Log(title = "购物车", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShopCar shopCar)
    {
        List<ShopCar> list = shopCarService.selectShopCarList(shopCar);
        ExcelUtil<ShopCar> util = new ExcelUtil<ShopCar>(ShopCar.class);
        return util.exportExcel(list, "购物车数据");
    }

    /**
     * 获取购物车详细信息
     */
    @ApiOperation(value = "获取购物车详细信息")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return AjaxResult.success(shopCarService.selectShopCarByCarId(carId));
    }

    /**
     * 新增购物车
     */
    @ApiOperation(value = "新增购物车")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopCar shopCar)
    {
        return toAjax(shopCarService.insertShopCar(shopCar));
    }

    /**
     * 修改购物车
     */
    @ApiOperation(value = "修改购物车")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopCar shopCar)
    {
        return toAjax(shopCarService.updateShopCar(shopCar));
    }

    /**
     * 删除购物车
     */
    @ApiOperation(value = "删除购物车")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(shopCarService.deleteShopCarByCarIds(carIds));
    }
}
